﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialFront.Providers.Image;
using SocialFront.Providers.Media;
using Image=SocialFront.Entities.Image;
using umbApi = umbraco;

namespace SocialFront.Web.usercontrols.Gallery
{
    public partial class EditImage : System.Web.UI.UserControl
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ((umbApi.UmbracoDefault)Page).ValidateRequest = false;
            Utilities.AddTinyMce();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void bEditImage_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                Entities.Media mediaItem = MediaProvider.Provider.UploadMedia(ImageFile, Config.sfMemberMediaNodeId.ToString());
                Image image = new Image
                                           {
                                               Title = imageTitle.Text,
                                               Content = imageDescription.Text,
                                               Media = mediaItem,
                                               Tags = Utilities.ConvertCsvToTags(imageTags.Text)
                                           };
                image = ImageProvider.Provider.CreateImage(image);
                Response.Redirect(image.PageUrl);
            }
        }
    }
}